﻿// -----------------------------------------------------------------------
// <copyright file="MyHttpServer.cs" company="Microsoft">
// nasic comands for web server
// </copyright>
// -----------------------------------------------------------------------

using WebServer.BusinessLogic.Communication;

namespace WebServer.BusinessLogic
{
    /// <summary>
    /// class for HttpServer simple commands
    /// </summary>
    public class MyHttpServer
    {
        /// <summary>
        /// Singleton for the Communicator
        /// </summary>
        public static Communicator Communicator = new Communicator();

        /// <summary>
        /// Starts listening
        /// </summary>
        public static void Start()
        {
            // create communicator with default handlers
           // Communicator = new Communicator();

            // give communicator command to start listening
            Communicator.StartListening();
        }

        /// <summary>
        /// Stops webserver and all the listening on any port
        /// </summary>
        public static void Stop()
        {
            Communicator.StopListening();

            // commented, because Communicator does that in Stop()
            //Communicator.LoadBalancer.StopAskingThread();
            //Communicator.LoadBalancer.StopAnsweringThread();
        }

        /// <summary>
        /// Restarts server by initiating Stop and Start consecutive
        /// </summary>
        public static void Restart()
        {
            Stop();

            Start();
        }
    }

    public interface IMyHttpServer
    {
        void Start();
        void Stop();
        void Restart();
    }
}
